/**
 * 查询首页头部图片的轮播图的信息
 */
//pc端的查询
(function () {
   $.ajax({
       type:'GET',
       dataType:'json',
       url:'/rest/front/slideshow/selectAllList',
       data:{type:'web'},
       success:function (data) {
           var list=data.data,html='<div class="swiper-wrapper">';
          $.each(list,function (i, e) {
              html+='<a href="'+e.url+'" class="swiper-slide"><img src="/'+e.image+'" style="height:370px">' +
                  '<h1></h1></a>'
          });
           $('.index-swiper').prepend(html);
           var swiperPg = new Swiper('.index-swiper', {
               pagination: '.swiper-pagination',
               paginationClickable: true,
               autoplayDisableOnInteraction: true,//开始自动播放,等到点击时不自动播放
               autoplay: 2500
           });
       }
   })
})();
//移动端的查询
(function () {
    $.ajax({
        type:'GET',
        dataType:'json',
        url:'/rest/front/slideshow/selectAllList',
        data:{type:'app'},
        success:function (data) {
            var list=data.data,html='<div class="swiper-wrapper">';
            $.each(list,function (i, e) {
                html+='<a href="'+e.url+'" class="swiper-slide"><img src="/'+e.image+'" style="height:240px">' +
                    '<h1></h1></a>'
            });
            $('.indexMobile-swiper').prepend(html);
            var swiperPgMobile = new Swiper('.indexMobile-swiper', {
                pagination: '.indexMobile-pagination',
                paginationClickable: true,
                autoplayDisableOnInteraction: true,//开始自动播放,等到点击时不自动播放
                autoplay: 2500
            });
        }
    })
})();
/**
 * 查询产品中心的系列，根据所系列显示相对应的内容（pc端）
 */
(function () {
    $.ajax({
        type:'GET',
        dataType:'json',
        url:'/rest/front/productcategory/selectAllList',
        success:function (data) {
            var list=data.data,html='',id='';
            $.each(list,function (i, e) {
                if(i==0){id=e.id}
              html+='<li data-id="'+e.id+'" onclick="queryProduct('+e.id+')"><img src="/'+e.icon+'" class="wsc-product-img  Show">' +
                  '<img src="/'+e.iconClick+'" class="wsc-product-img Hide">' +
                  '<span class="c-tab-tit">'+e.name+'</span></li>'
            });
            $('.c-tab-normal').html(html);
            $(".c-tab-normal li:first-child").addClass('active');
            $(".c-tab-normal li").click(function(){
                $(this).addClass('active').siblings().removeClass('active');
            });
            return queryProduct(id);
        }
    })
})();
function queryProduct(id){
    $.ajax({
        type:'GET',
        url:'/rest/front/product/selectAllList',
        data:{categoryID:id},
        dataType:'json',
        success:function (data) {
            var list=data.data,html='';
            $.each(list,function (i,e) {
                html+='<li class="home-product-item"><a href="../cpzx/cpxl/'+e.id+'.html">' +
                    '<h3>'+e.name+'</h3><p>'+e.introduce+'</p><i class="iconfont icon-more"></i></a></li>'
            });
            $('.productTab-list').html(html);
            dotNav();
        }
    })
}

/**
 * 查询产品中心的系列，根据所系列显示相对应的内容（移动端）
 */
(function () {
    $.ajax({
        type:'GET',
        dataType:'json',
        url:'/rest/front/product/selectProductList',
        success:function (data) {
            var list=data.data,html='';
            $.each(list,function (i, o) {
                html+='<div class="productMobile-box">' +
                    '<div class="mb10 j-product"> <img src="/'+o.icon+'" class="wsc-product-img  Show" style="margin:0 12px 0 0;"><img src="/'+o.iconClick+'" class="wsc-product-img  Hide" style="margin:0 12px 0 0;"><div class="cell-main">'+o.name+'</div><div class="circle-btn"> <i class="iconfont icon-jiantouxia"></i></div>'+
                    '</div><div class="productMobileToggle Hide "><ul class="productToggle-ul">';
                $.each(o.productList,function(i,e){
                    html+='<li><a><h3>'+e.name+'</h3><p>'+e.introduce+'</p></a></li>'
                });
                html+='</ul></div></div>';
            });
            $(".productMobile-list").html(html);
            $(".productMobile-box:first-child").addClass('active');
            $(".productMobile-box").click(function(){
                $(this).addClass('active').siblings().removeClass('active');
            });
            $('.j-product').click(function () {
                var btn = $(this).find('i');
                btn.hasClass('icon-jiantouxia') ? btn.removeClass('icon-jiantouxia').addClass(
                    'icon-jiantoushang') : btn.removeClass(
                    'icon-jiantoushang').addClass('icon-jiantouxia');
                $(this).siblings('.productMobileToggle').slideToggle("slow");
                $(this).parents('.productMobile-box ').siblings().find('.productMobileToggle').hide();
                $(this).parents('.productMobile-box').siblings().find('i').removeClass(
                    'icon-jiantoushang').addClass('icon-jiantouxia')
            });
        }
    })
})();

/**
 * 查询解决方案
 */
(function () {
    $.ajax({
        type:'GET',
        dataType:'json',
        url:'/rest/front/plancategory/selectAllList',
        success:function (data) {
            var list=data.data,html='',id='';
            $.each(list,function (i, e) {
                if(i<3){
                    if(i==0){id=e.id}
                    html+='<li data-id="'+e.id+'">'+e.name+'</li>';
                    if(i>2){
                        return false;
                    }
                }
            });
            $('.solutionPc-nav').html(html).find('li').eq(0).addClass('active');
            $('.solutionMobile-nav').html(html).find('li').eq(0).addClass('active');
            return queryplan(id);
        }
    })
})();
function queryplan(id) {
    $.ajax({
        type:'GET',
        url:'/rest/front/plan/selectAllList',
        data:{categoryID:id},
        dataType:'json',
        success:function (data) {
            var list=data.data,html='',imgHtml='';
            $.each(list,function (i,e) {
                if(i<4){
                html+='<li><a href="./jjfa.html?categoryID='+id+'"><img src="/'+e.icon +'" alt="" width="200" height="150">' +
                    '<p class="indexImg-p text-center">'+e.name+'</p></li></a>';
                imgHtml+='<div class="swiper-slide"><a>';
                imgHtml+='<img src="/'+e.icon+'" alt="" width="150" height="90"> <p>'+e.name+'</p></a></div>'
                }
            });
            $('.j-plan').html(html);
            $('.solutionMobile-swiper-wrapper').html(imgHtml);

        }
    })
}
/**
 * 查询资讯的分类信息
 */
(function () {
    $.ajax({
        type:'GET',
        dataType:'json',
        url:'/rest/front/news/selectAllList',
        data:{categoryName:'企业新闻'},
        success:function (data) {
            var list=data.data,html='',singnews='';
            $.each(list,function (i, e) {
                var time=e.createTime.split(' ')[0];
                if(i==0){
                    html='<a href="../zlkx/'+e.id+'.html"><img src="/'+e.headImage+'" class="pull-left" width="150" height="120">' +
                        '<div class="pull-left"><h6>'+e.name+'</h6><p>'+e.introduce+'</p><span><i class="iconfont icon-ai253 pull-left"></i>' +
                        '<p class="pull-left">'+time+'</p></span></div></a>'
                }else if(i<5){
                    singnews+='<li><a href="../zlkx/'+e.id+'.html"><p class="pull-left">'+e.name+'</p>' +
                        '<p class="pull-right">'+time+'</p></li></a>'
                }else{
                    return false;
                }
            });
            $('.j-company,.jMobile-company').html(html);
            $('.c-singer,.cMobile-singer').html(singnews);
            newDots();

        }
    })
})();

(function () {
    $.ajax({
        type:'GET',
        dataType:'json',
        url:'/rest/front/news/selectAllList',
        data:{categoryName:'行业动态'},
        success:function (data) {
            var list=data.data,html='',singnews='';
            $.each(list,function (i, e) {
                var time=e.createTime.split(' ')[0];
                if(i==0){
                    html='<a href="../zlkx/'+e.id+'.html"><img src="/'+e.headImage+'" class="pull-left" width="150" height="120">' +
                        '<div class="pull-left"><h6>'+e.name+'</h6><p>'+e.introduce+'</p><span><i class="iconfont icon-ai253 pull-left"></i>' +
                        '<p class="pull-left">'+time+'</p></span></div></a>'
                }else if(i<5){
                    singnews+='<li><a href="../zlkx/'+e.id+'.html"><p class="pull-left">'+e.name+'</p>' +
                        '<p class="pull-right">'+time+'</p></a></li>'
                }else{
                    return false;
                }
            });
            $('.j-industry,.jMobile-industry').html(html);
            $('.in-singer,.cMobile-industry').html(singnews);
            newDots();

        }
    })
})();

$(function () {
    //解决方案的tab转换的效果
    $('.solutionPc-nav,.solutionMobile-nav').on('click', 'li', function() {
        var id=$(this).data('id');
        $(this).addClass('active').siblings().removeClass('active');
        queryplan(id)
    });
    //点击更多，跳转到资讯中心，但是要带各自的类型参数
    $(".moreBtn").click(function(){
        window.location.href="./zlkx.html?categoryName=企业新闻";
    });
    $(".moreBtn1").click(function(){
        window.location.href="./zlkx.html?categoryName=行业动态";
    });

});
function newDots(){
    $(".j-company div p,.j-industry div p").each(function(){
        var maxwidth=48;
        if($(this).text().length >maxwidth){
            $(this).text($(this).text().substring(0,maxwidth));
            $(this).html($(this).html()+'...');
        }
    });
}